package com.android.meige.utils;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

import com.android.meige.activity.mine.LoginActivity;


/**
 * Created by Administrator on 2016/8/19.
 */
public class LoginState {


    private static LoginState instance = new LoginState();

    private LoginState() {

    }

    public static LoginState getInstance() {
        return instance;
    }

    public boolean isLogin(Context context) {
        // 读取sp
        SharedPreferences sp = context.getSharedPreferences(ConstantsUrl.USERDATA, 0);
        String threeid = sp.getString(ConstantsUrl.USERDATA_UID, "");
        String threepd = sp.getString(ConstantsUrl.USERDATA_UPSW, "");
        return !"".equals(threeid) || !"".equals(threepd);
    }

    public void startActivity(Context context, Class clazz) {

        if (LoginState.getInstance().isLogin(context)) {

            context.startActivity(new Intent(context, clazz));

        } else {

            context.startActivity(new Intent(context, LoginActivity.class));
        }
    }

    public String getid(Context context) {
        SharedPreferences sp = context.getSharedPreferences(ConstantsUrl.USERDATA, 0);
        String threeid = sp.getString(ConstantsUrl.USERDATA_UID, "");
        return threeid;
    }

    public String getpd(Context context) {

        SharedPreferences sp = context.getSharedPreferences(ConstantsUrl.USERDATA, 0);
        String threepd = sp.getString(ConstantsUrl.USERDATA_UPSW, "");
        return threepd;


    }

    public String getUserInfo(Context context, int type) {

        SharedPreferences sp = context.getSharedPreferences(ConstantsUrl.USERDATA, 0);
        String threename = sp.getString(ConstantsUrl.USERDATA_NAME, "");
        String threephoto = sp.getString(ConstantsUrl.USERDATA_AVATAR, "");
        int threeplogintype = sp.getInt(ConstantsUrl.USERDATA_TYPE, 0);
        String threezone = sp.getString(ConstantsUrl.USERDATA_ZONE,"");
        String threecity = sp.getString(ConstantsUrl.USERDATA_CITY,"");
        switch (type) {
            case 0:
                return threename;
            case 1:
                return threephoto;
            case 2:
                return threezone;
            case 3:
                return threecity;
            default:
                return threeplogintype + "";
        }


    }


}
